#==============================================================#
# File      :   pgbouncer.conf
# Desc      :   Pgbouncer Main Config for {{ pg_instance }}
# Time      :   {{ '%Y-%m-%d %H:%M' | strftime }}
# Host      :   {{ pg_instance }} @ {{ inventory_hostname }}:{{ pg_port }}
# Path      :   /etc/pgbouncer/pgbouncer.ini
# Note      :   ANSIBLE MANAGED, DO NOT CHANGE!
# Author    :   Ruohang Feng (rh@vonng.com)
# License   :   AGPLv3
#==============================================================#

[users]
%include /etc/pgbouncer/useropts.txt

[databases]
%include /etc/pgbouncer/database.txt

[pgbouncer]
pool_mode                   = {{ pgbouncer_poolmode }}
listen_addr                 = *
listen_port                 = {{ pgbouncer_port }}
auth_type                   = hba
auth_file                   = /etc/pgbouncer/userlist.txt
auth_hba_file               = /etc/pgbouncer/pgb_hba.conf
{% if pgbouncer_auth_query|bool %}
auth_user                   = {{ pg_dbsu }}
auth_query                  = SELECT username, password FROM monitor.pgbouncer_auth($1)
{% endif %}
admin_users                 = {{ pg_dbsu }}, {{ pg_admin_username }}
stats_users                 = {{ pg_dbsu }}, {{ pg_monitor_username }}
server_reset_query          =
pidfile                     = /var/run/postgresql/pgbouncer.pid
logfile                     = {{ pgbouncer_log_dir }}/pgbouncer.log
unix_socket_dir             = /var/run/postgresql
application_name_add_host   = 1
max_client_conn             = 20000
min_pool_size               = 0
default_pool_size           = 32
reserve_pool_size           = 32
reserve_pool_timeout        = 1
max_db_connections          = 100
max_user_connections        = 100
server_round_robin          = 0
log_connections             = 0
log_disconnections          = 0
ignore_startup_parameters   = extra_float_digits
client_tls_sslmode          = {{ pgbouncer_sslmode }}
client_tls_cert_file        = /pg/cert/server.crt
client_tls_key_file         = /pg/cert/server.key
client_tls_ca_file          = /etc/pki/ca.crt
